package com.yangwp.jie.controller;

import com.yangwp.jie.common.enums.RetCodeEnum;
import com.yangwp.jie.common.utils.MapUtils;
import com.yangwp.jie.model.JieUser;
import com.yangwp.jie.service.JieUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@RequestMapping("/jie/register")
@Controller
public class RegisterController {

    @Autowired
    private JieUserService jieUserService;

    @RequestMapping("")
    public String register(){
        return "/main/register.ftl";
    }

    @RequestMapping("/save")
    @ResponseBody
    public Map<String, Object> save(@RequestBody JieUser user){

        if(jieUserService.add(user)){
            return MapUtils.getRetMap(RetCodeEnum.SUCCESS);
        }
        return MapUtils.getRetMap(RetCodeEnum.SERVER_FAIL);
    }
}
